package com.meet.bizservice.impl;

import com.meet.persist.dao.ActivityDao;
import com.meet.api.dto.response.MeetActivityTrendDataResponseDTO;
import com.meet.api.dto.response.MeetStatisticsDataResponseDTO;
import com.meet.exception.BusinessException;
import com.meet.bizservice.StatisticsService;
import com.meet.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class StatisticsServiceImpl implements StatisticsService {

    private static final Logger logger = LoggerFactory.getLogger(StatisticsServiceImpl.class);

    @Autowired
    private ActivityDao activityDao;

    @Override
    public Result<MeetStatisticsDataResponseDTO> getUserParticipationStats() {
        try {
            logger.info("Getting user participation statistics");

            // 这里应该从JWT中获取用户ID，为简化演示直接返回示例数据
            MeetStatisticsDataResponseDTO stats = new MeetStatisticsDataResponseDTO();
            stats.setTotalActivities(15);
            stats.setAttendedActivities(8);
            stats.setCreatedActivities(3);

            return Result.success(stats);
        } catch (Exception e) {
            logger.error("Error getting user participation stats", e);
            throw new BusinessException("获取用户参与统计失败");
        }
    }

    @Override
    public Result<List<MeetActivityTrendDataResponseDTO>> getActivityTrendStats(String timePeriod) {
        try {
            logger.info("Getting activity trend statistics for period: {}", timePeriod);

            // 这里应该从JWT中获取用户ID，为简化演示直接返回示例数据
            MeetActivityTrendDataResponseDTO data1 = new MeetActivityTrendDataResponseDTO();
            data1.setDate("2023-01-01");
            data1.setActivityCount(5);

            MeetActivityTrendDataResponseDTO data2 = new MeetActivityTrendDataResponseDTO();
            data2.setDate("2023-01-02");
            data2.setActivityCount(8);

            return Result.success(Arrays.asList(data1, data2));
        } catch (Exception e) {
            logger.error("Error getting activity trend stats", e);
            throw new BusinessException("获取活动趋势统计失败");
        }
    }
}
